import { createRouter, createWebHashHistory } from "vue-router";

export const Layout = () => import("@/layout/index.vue");

// 静态路由
export const constantRoutes = [
  // {
  //   path: "/redirect",
  //   component: Layout,
  //   meta: { hidden: true },
  //   children: [
  //     {
  //       path: "/redirect/:path(.*)",
  //       component: () => import("@/views/redirect/index.vue"),
  //     },
  //   ],
  // },

  {
    path: "/login",
    component: () => import("@/views/login/index.vue"),
    meta: { hidden: true },
  },

  {
    path: "/",
    name: "/",
    component: Layout,
    redirect: "/dashboard",
    children: [
      {
        path: "dashboard",
        component: () => import("@/views/dashboard/index.vue"),
        // 用于 keep-alive 功能，需要与 SFC 中自动推导或显式声明的组件名称一致
        // 参考文档: https://cn.vuejs.org/guide/built-ins/keep-alive.html#include-exclude
        name: "Dashboard",
        meta: {
          title: "工作台",
          icon: "homepage",
          affix: true,
          keepAlive: true,
          hidden: true
        },
      },

    ],
  },
  {
    path: "/component",
    component: "Layout",
    name: "/component",
    meta: {
      title: "组件封装",
      icon: "menu",
      hidden: false,
      alwaysShow: false,
      params: null,
    },
    children: [
      {
        path: "curd",

        component: () => import("@/views/demo/curd/index.vue"),
        name: "Curd",
        meta: {
          title: "增删改查",
          icon: "",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "table-select",
        component: () => import("@/views/demo/table-select/index.vue"),
        name: "TableSelect",
        meta: {
          title: "列表选择器",
          icon: "",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "wang-editor",
        component: () => import("@/views/demo/wang-editor.vue"),
        name: "WangEditor",
        meta: {
          title: "富文本编辑器",
          icon: "",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "upload",
        component: () => import("@/views/demo/upload.vue"),
        name: "Upload",
        meta: {
          title: "图片上传",
          icon: "",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "dict-demo",
        component: () => import("@/views/demo/dictionary"),
        name: "DictDemo",
        meta: {
          title: "字典组件",
          icon: "",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "icon-selector",
        component: () => import("@/views/demo/icon-selector"),
        name: "IconSelector",
        meta: {
          title: "图标选择器",
          icon: "",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "drag",
        component: () => import("@/views/demo/drag"),
        name: "Drag",
        meta: {
          title: "拖拽组件",
          icon: "",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
      {
        path: "text-scroll",
        component: () => import("@/components/TextScroll"),
        name: "TextScroll",
        meta: {
          title: "滚动文本",
          icon: "",
          hidden: false,
          keepAlive: true,
          alwaysShow: false,
          params: null,
        },
      },
    ],
  },
];

/**
 * 创建路由
 */
const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoutes,
  // 刷新时，滚动条位置还原
  scrollBehavior: () => ({ left: 0, top: 0 }),
});

// 全局注册 router
export function setupRouter(app) {
  app.use(router);
}

export default router; 
